package com.whw.fy.controller;

import com.alibaba.fastjson.JSON;
import com.whw.fy.entity.AttendanceStu;
import com.whw.fy.entity.Message;
import com.whw.fy.service.AttendanceStuService;
import com.whw.fy.service.AttendanceTeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = "学生考勤模块")
@RestController
@RequestMapping("/api/attendanceStu")
public class AttendanceStuController {
    @Resource
    private AttendanceStuService attendanceStuService;

    @ApiOperation(value = "添加考勤信息")
    @PostMapping("/one")
    public Message insert(AttendanceStu attendanceStu) {
        return attendanceStuService.insertSelective(attendanceStu);
    }

    @ApiOperation(value = "批量添加考勤信息(传入List<AttendanceStu>)")
    @PostMapping("/all")
    public Message batchInsert(int classId,String list) {
       List<AttendanceStu> attendanceStuList = JSON.parseArray(list,AttendanceStu.class);
        return attendanceStuService.batchInsert(classId,attendanceStuList);
    }

    @ApiOperation(value = "根据考勤id删除考勤信息")
    @DeleteMapping("/")
    public Message delete(Integer attStuId) {
        return attendanceStuService.deleteByPrimaryKey(attStuId);
    }

    @ApiOperation(value = "根据考勤id修改考勤信息")
    @PutMapping("/")
    public Message update(AttendanceStu attendanceStu) {
        return attendanceStuService.updateByPrimaryKeySelective(attendanceStu);
    }

    @ApiOperation(value = "获取所有学生考勤")
    @GetMapping("/all")
    public Message selectAll(){
        return attendanceStuService.selectAll();
    }

    @ApiOperation(value = "根据考勤id获取学生考勤记录")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer attStuId){
        return attendanceStuService.selectByPrimaryKey(attStuId);
    }

    @ApiOperation(value = "根据班级id和上课次数获得学生出勤记录（小程序用）")
    @GetMapping("/selectStudentByClassIDAndCompletionTimes")
    public Message selectStudentByClassIDAndCompletionTimes(int classId,int CompletionTimes){
        return attendanceStuService.selectStudentByClassIDAndCompletionTimes(classId, CompletionTimes);
    }

    @ApiOperation(value = "根据班级id和上课次数获得学生出勤记录（管理端用）")
    @GetMapping("/selectStudentByClassIDAndCompletionTimes/Admin")
    public Message selectStudentByClassIDAndCompletionTimesAdmin(int classId,int CompletionTimes){
        return attendanceStuService.selectStudentByClassIDAndCompletionTimesAdmin(classId, CompletionTimes);
    }


    @ApiOperation(value = "根据学生id和出勤情况获得学生出勤记录")
    @GetMapping("/selectByStudentIdAndAttendance")
    public Message selectByStudentIdAndAttendance(int studentId,int attendance){
        return attendanceStuService.selectByStudentIdAndAttendance(studentId, attendance);
    }

    @ApiOperation(value = "根据学生id获得学生出勤记录")
    @GetMapping("/selectByStudentId")
    public Message selectByStudentId(int studentId){
        return attendanceStuService.selectByStudentId(studentId);
    }

    @ApiOperation(value = "根据学生id、上课次数和上课班级获得学生出勤记录")
    @GetMapping("/selectByStudentIdAndCompletionTimesAndClassId")
    public Message selectAllByStudentIdAndCompletionTimesAndClassId(Integer studentId, Integer completionTimes, Integer classId){
        return attendanceStuService.selectAllByStudentIdAndCompletionTimesAndClassId(studentId,completionTimes,classId);
    }

}
